{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "828f8752-76df-45bc-bb91-c5530ed11478",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "3b7c20074f21486ab3b8449fd610a5c5",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(IntSlider(value=5000, description='fix_cost', max=15000, min=-5000), IntSlider(value=10,…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<function __main__.plot_sensitivity(fix_cost=5000, marginal_cost=10, price=10)>"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from matplotlib.font_manager import FontProperties\n",
    "from matplotlib import rc\n",
    "from ipywidgets import interact\n",
    "\n",
    "# 指定默认字体为中文字体\n",
    "rc(\"font\",family='YouYuan')\n",
    "\n",
    "# 设置字体为微软雅黑 - 用于轴标签\n",
    "my_font = FontProperties(fname=r\"..\\fonts\\DingTalkJinBuTi-Regular.ttf\")\n",
    "\n",
    "def plot_sensitivity(fix_cost=5000, marginal_cost=10, price=10):\n",
    "    sale_volume=np.linspace(0,3000, 300)\n",
    "    fix_cost = np.array([0] + [fix_cost] * 299)\n",
    "    cost = fix_cost + marginal_cost * sale_volume\n",
    "    income = price * sale_volume\n",
    "    \n",
    "    # 绘制 成本线\n",
    "    plt.plot(sale_volume, cost, label='成本', color='red')\n",
    "    # 绘制 收入线\n",
    "    plt.plot(sale_volume, income, label='收入', color='blue')\n",
    "    # 设置坐标轴标签\n",
    "    plt.xlabel('销售数量', fontproperties=my_font)\n",
    "    plt.ylabel('金额', fontproperties=my_font)\n",
    "    # 设置图例\n",
    "    plt.legend()\n",
    "\n",
    "    plt.ylim(0, 50000)\n",
    "\n",
    "    plt.show()\n",
    "\n",
    "interact(plot_sensitivity, price=(5, 30))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8ba54364",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
